<?php

class costabravaComponents extends sfComponents
{
	public function executeMostRecentVillages(){
		$q = Doctrine::getTable('Villages')->createQuery('v')
		  ->where('v.visible = ?', '1')
		  ->orderBy('v.updated_at DESC')->limit(10);
		$this->mostRecentVillages= $q->execute();
	}
	
	public function executeNordSudVillages(){
		
		$qNord = Doctrine::getTable('Villages')->createQuery('v')
		  ->where('v.visible = ?', '1')
		  ->andWhere('v.geolatitud >= ?', 42.15)
		  ->orderBy('v.geolatitud DESC')->limit(10);
		$this->nordVillages= $qNord->execute();		

		$qCentre = Doctrine::getTable('Villages')->createQuery('v')
		  ->where('v.visible = ?', '1')
		  ->andWhere('v.geolatitud BETWEEN ? AND ?', array(41.819172, 42.15))
		  ->orderBy('v.geolatitud DESC')->limit(10);
		$this->centreVillages= $qCentre->execute();
		
		$qSud = Doctrine::getTable('Villages')->createQuery('v')
		  ->where('v.visible = ?', '1')
		  ->andWhere('v.geolatitud <= ?', 41.819172)
		  ->orderBy('v.geolatitud DESC')->limit(10);
		$this->sudVillages= $qSud->execute();
	}
	
	public function executeVillageViviendas(){
		//Appt
		$q = Doctrine_Query::create()
		->select('v.*')
		->from('ViviendasAlquileres v')
		->leftJoin('v.ZonasViviendas z ON v.zona=z.zona')
		->andWhere('v.activo = ?', 's')
		->andWhere('z.municipio = ?', $this->nomVillage)
		->andWhere('v.apart_casa = ?', 0);
		
		$this->villageViviendasAppt = $q->execute();
		
		//Villas
		$q = Doctrine_Query::create()
		->select('v.*')
		->from('ViviendasAlquileres v')
		->leftJoin('v.ZonasViviendas z ON v.zona=z.zona')
		->andWhere('v.activo = ?', 's')
		->andWhere('z.municipio = ?', $this->nomVillage)
		->andWhere('v.apart_casa = ?', 1);
		
		$this->villageViviendasVillas = $q->execute();
	}
}
?>
